---
id: pop
title: Pop Node
sidebar_label: Pop
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

![Pop Node Screenshot](./assets/pop-node.png)

## Overview

The Pop Node is used to remove either the first or last element from an array and output both the removed element and the remaining array. By default, the Pop Node will pop the last element from the array.

This node is useful when you want to process elements of an array one by one in a loop.

<Tabs
  defaultValue="inputs"
  values={[
    {label: 'Inputs', value: 'inputs'},
    {label: 'Outputs', value: 'outputs'},
    {label: 'Editor Settings', value: 'settings'},
  ]
}>

<TabItem value="inputs">

## Inputs

| Title | Data Type | Description           | Default Value | Notes                                                          |
| ----- | --------- | --------------------- | ------------- | -------------------------------------------------------------- |
| Array | `any[]`   | The array to pop from | (required)    | The input will be coerced into an array if it is not an array. |

</TabItem>

<TabItem value="outputs">

## Outputs

| Title | Data Type | Description                                                                         | Notes |
| ----- | --------- | ----------------------------------------------------------------------------------- | ----- |
| Last  | `any`     | The last element of the array, or the first element if "Pop from front" is enabled. |       |
| Rest  | `any[]`   | The remaining elements of the array after the last element is popped.               |       |

</TabItem>

<TabItem value="settings">

## Editor Settings

| Setting        | Description                                                                    | Default Value | Use Input Toggle | Input Data Type |
| -------------- | ------------------------------------------------------------------------------ | ------------- | ---------------- | --------------- |
| Pop from front | If enabled, the first element of the array will be popped instead of the last. | False         | No               | N/A             |

</TabItem>

</Tabs>

## Example 1: Pop the last element from an array

1. Create an [Array Node](./array.mdx) and set the values to `["John", "Doe", "30", "Engineer"]`.
2. Create a Pop Node and connect the Array Node to its `Array` input.
3. Run the graph. The `Last` output of the Pop Node should be `"Engineer"` and the `Rest` output should be `["John", "Doe", "30"]`.

![Pop Node Example 1](./assets/pop-node-example-01.png)

## Example 2: Pop the first element from an array

1. Create an [Array Node](./array.mdx) and set the values to `["John", "Doe", "30", "Engineer"]`.
2. Create a Pop Node, enable the `Pop from front` setting, and connect the Array Node to its `Array` input.
3. Run the graph. The `Last` output of the Pop Node should be `"John"` and the `Rest` output should be `["Doe", "30", "Engineer"]`.

![Pop Node Example 2](./assets/pop-node-example-02.png)

## Error Handling

The Pop Node will error if the `Array` input is not provided, is not an array, or is an empty array.

## FAQ

**Q: Can I pop multiple elements from an array at once?**

A: No, the Pop Node can only pop one element at a time. If you want to remove multiple elements from an array, you can use multiple Pop Nodes in a sequence.

**Q: Can I use the Pop Node to pop elements from a string?**

A: No, the Pop Node only works with arrays. If you want to remove characters from a string, you can use a [Code Node](./code.mdx) with custom JavaScript code.

**Q: What if the array is empty?**

A: The Pop Node will error if the array is empty. You can use an [If Node](./if.mdx) to check if the array is empty before popping from it.

## See Also

- [Array Node](./array.mdx)
- [Slice Node](./slice.mdx)
- [Code Node](./code.mdx)
- [Loop Controller Node](./loop-controller.mdx)
